﻿using System;
using System.Reflection;

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }
}

class Program
{
    static void Main()
    {
        try
        {
            Type personType = typeof(Person);

            object[] constructorParams = { "John", 30 };

            // 获取构造方法信息
            ConstructorInfo constructor = personType.GetConstructor(new Type[] { typeof(string), typeof(int) });

            // 使用反射调用构造方法创建实例
            object personInstance = constructor.Invoke(constructorParams);

            Person person = (Person)personInstance;
            Console.WriteLine($"姓名: {person.Name}, 年龄: {person.Age}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}  
